<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>removeformatting_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_removeformatting_test.js.html">removeformatting_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.RemoveFormattingTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.RemoveFormattingTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line21"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line22"></a>goog.require(&#39;goog.editor.plugins.RemoveFormatting&#39;);
<a name="line23"></a>goog.require(&#39;goog.string&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.dom&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line28"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line29"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line30"></a>
<a name="line31"></a>var SAVED_HTML;
<a name="line32"></a>var FIELDMOCK;
<a name="line33"></a>var FORMATTER;
<a name="line34"></a>var testHelper;
<a name="line35"></a>var WEBKIT_BEFORE_CHROME_8;
<a name="line36"></a>var WEBKIT_AFTER_CHROME_16;
<a name="line37"></a>var WEBKIT_AFTER_CHROME_21;
<a name="line38"></a>var insertImageBoldGarbage = &#39;&#39;;
<a name="line39"></a>var insertImageFontGarbage = &#39;&#39;;
<a name="line40"></a>var controlHtml;
<a name="line41"></a>var controlCleanHtml;
<a name="line42"></a>var expectedFailures;
<a name="line43"></a>
<a name="line44"></a>function setUpPage() {
<a name="line45"></a>  WEBKIT_BEFORE_CHROME_8 = goog.userAgent.WEBKIT &amp;&amp;
<a name="line46"></a>      !goog.userAgent.isVersionOrHigher(&#39;534.10&#39;);
<a name="line47"></a>
<a name="line48"></a>  WEBKIT_AFTER_CHROME_16 = goog.userAgent.WEBKIT &amp;&amp;
<a name="line49"></a>      goog.userAgent.isVersionOrHigher(&#39;535.7&#39;);
<a name="line50"></a>
<a name="line51"></a>  WEBKIT_AFTER_CHROME_21 = goog.userAgent.WEBKIT &amp;&amp;
<a name="line52"></a>      goog.userAgent.isVersionOrHigher(&#39;537.1&#39;);
<a name="line53"></a>  // On Chrome 16, execCommand(&#39;insertImage&#39;) inserts a garbage BR
<a name="line54"></a>  // after the image that we insert. We use this command to paste HTML
<a name="line55"></a>  // in-place, because it has better paragraph-preserving semantics.
<a name="line56"></a>  //
<a name="line57"></a>  // TODO(nicksantos): Figure out if there are better chrome APIs that we
<a name="line58"></a>  // should be using, or if insertImage should just be fixed.
<a name="line59"></a>  if (WEBKIT_AFTER_CHROME_21) {
<a name="line60"></a>    insertImageBoldGarbage = &#39;&lt;br&gt;&#39;;
<a name="line61"></a>    insertImageFontGarbage = &#39;&lt;br&gt;&#39;;
<a name="line62"></a>  } else if (WEBKIT_AFTER_CHROME_16) {
<a name="line63"></a>    insertImageBoldGarbage = &#39;&lt;b&gt;&lt;br/&gt;&lt;/b&gt;&#39;;
<a name="line64"></a>    insertImageFontGarbage = &#39;&lt;font size=&quot;1&quot;&gt;&lt;br/&gt;&lt;/font&gt;&#39;;
<a name="line65"></a>  }
<a name="line66"></a>  // Extra html to add to test html to make sure removeformatting is actually
<a name="line67"></a>  // getting called when you&#39;re testing if it leaves certain styles alone
<a name="line68"></a>  // (instead of not even running at all due to some other bug). However, adding
<a name="line69"></a>  // this extra text into the node to be selected screws up IE.
<a name="line70"></a>  // (e.g. &lt;a&gt;&lt;img&gt;&lt;/a&gt;&lt;b&gt;t&lt;/b&gt; --&gt; &lt;a&gt;&lt;/a&gt;&lt;a&gt;&lt;img&gt;&lt;/a&gt;t )
<a name="line71"></a>  // TODO(user): Remove this special casing once http://b/3131117 is
<a name="line72"></a>  // fixed.
<a name="line73"></a>  controlHtml = goog.userAgent.IE ? &#39;&#39; : &#39;&lt;u&gt;control&lt;/u&gt;&#39;;
<a name="line74"></a>  controlCleanHtml = goog.userAgent.IE ? &#39;&#39; : &#39;control&#39;;
<a name="line75"></a>  expectedFailures = new goog.testing.ExpectedFailures();
<a name="line76"></a>}
<a name="line77"></a>
<a name="line78"></a>function setUp() {
<a name="line79"></a>  testHelper = new goog.testing.editor.TestHelper(
<a name="line80"></a>      document.getElementById(&#39;html&#39;));
<a name="line81"></a>  testHelper.setUpEditableElement();
<a name="line82"></a>
<a name="line83"></a>  FIELDMOCK = new goog.testing.editor.FieldMock();
<a name="line84"></a>  FIELDMOCK.getElement();
<a name="line85"></a>  FIELDMOCK.$anyTimes();
<a name="line86"></a>  FIELDMOCK.$returns(document.getElementById(&#39;html&#39;));
<a name="line87"></a>
<a name="line88"></a>  FORMATTER = new goog.editor.plugins.RemoveFormatting();
<a name="line89"></a>  FORMATTER.fieldObject = FIELDMOCK;
<a name="line90"></a>
<a name="line91"></a>  FIELDMOCK.$replay();
<a name="line92"></a>}
<a name="line93"></a>
<a name="line94"></a>function tearDown() {
<a name="line95"></a>  expectedFailures.handleTearDown();
<a name="line96"></a>  testHelper.tearDownEditableElement();
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>function setUpTableTests() {
<a name="line100"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line101"></a>  div.innerHTML = &#39;&lt;table&gt;&lt;tr&gt; &lt;th&gt; head1&lt;/th&gt;&lt;th id= &quot;outerTh&quot;&gt;&#39; +
<a name="line102"></a>      &#39;&lt;span id=&quot;emptyTh&quot;&gt;head2&lt;/span&gt;&lt;/th&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt; one &lt;/td&gt; &lt;td&gt;&#39; +
<a name="line103"></a>      &#39;two &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt; three&lt;/td&gt;&lt;td id=&quot;outerTd&quot;&gt; &#39; +
<a name="line104"></a>      &#39;&lt;span id=&quot;emptyTd&quot;&gt;&lt;strong&gt;four&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&#39; +
<a name="line105"></a>      &#39;&lt;tr id=&quot;outerTr&quot;&gt;&lt;td&gt;&lt;span id=&quot;emptyTr&quot;&gt; five &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&#39; +
<a name="line106"></a>      &#39;&lt;tr id=&quot;outerTr2&quot;&gt;&lt;td id=&quot;cell1&quot;&gt;&lt;b&gt;seven&lt;/b&gt;&lt;/td&gt;&lt;td id=&quot;cell2&quot;&gt;&#39; +
<a name="line107"></a>      &#39;&lt;u&gt;eight&lt;/u&gt;&lt;span id=&quot;cellspan2&quot;&gt; foo&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line108"></a>}
<a name="line109"></a>
<a name="line110"></a>function testTableTagsAreNotRemoved() {
<a name="line111"></a>  setUpTableTests();
<a name="line112"></a>  var span;
<a name="line113"></a>
<a name="line114"></a>  // TD
<a name="line115"></a>  span = document.getElementById(&#39;emptyTd&#39;);
<a name="line116"></a>  goog.dom.Range.createFromNodeContents(span).select();
<a name="line117"></a>  FORMATTER.removeFormatting_();
<a name="line118"></a>
<a name="line119"></a>  var elem = document.getElementById(&#39;outerTd&#39;);
<a name="line120"></a>  assert(&#39;TD should not be removed&#39;, !!elem);
<a name="line121"></a>  if (!goog.userAgent.WEBKIT) {
<a name="line122"></a>    // webkit seems to have an Apple-style-span
<a name="line123"></a>    assertEquals(&#39;TD should be clean&#39;, &#39;four&#39;,
<a name="line124"></a>        goog.string.trim(elem.innerHTML));
<a name="line125"></a>  }
<a name="line126"></a>
<a name="line127"></a>  // TR
<a name="line128"></a>  span = document.getElementById(&#39;outerTr&#39;);
<a name="line129"></a>  goog.dom.Range.createFromNodeContents(span).select();
<a name="line130"></a>  FORMATTER.removeFormatting_();
<a name="line131"></a>
<a name="line132"></a>  var elem = document.getElementById(&#39;outerTr&#39;);
<a name="line133"></a>  assert(&#39;TR should not be removed&#39;, !!elem);
<a name="line134"></a>
<a name="line135"></a>  // TH
<a name="line136"></a>  span = document.getElementById(&#39;emptyTh&#39;);
<a name="line137"></a>  goog.dom.Range.createFromNodeContents(span).select();
<a name="line138"></a>  FORMATTER.removeFormatting_();
<a name="line139"></a>
<a name="line140"></a>  var elem = document.getElementById(&#39;outerTh&#39;);
<a name="line141"></a>  assert(&#39;TH should not be removed&#39;, !!elem);
<a name="line142"></a>  if (!goog.userAgent.WEBKIT) {
<a name="line143"></a>    // webkit seems to have an Apple-style-span
<a name="line144"></a>    assertEquals(&#39;TH should be clean&#39;, &#39;head2&#39;, elem.innerHTML);
<a name="line145"></a>  }
<a name="line146"></a>
<a name="line147"></a>}
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * We select two cells from the table and then make sure that there is no
<a name="line152"></a> * data loss and basic formatting is removed from each cell.
<a name="line153"></a> */
<a name="line154"></a>function testTableDataIsNotRemoved() {
<a name="line155"></a>  setUpTableTests();
<a name="line156"></a>  if (goog.userAgent.IE) {
<a name="line157"></a>    // IE returns an &quot;unspecified error&quot; which seems to be beyond
<a name="line158"></a>    // ExpectedFailures&#39; ability to catch.
<a name="line159"></a>    return;
<a name="line160"></a>  }
<a name="line161"></a>
<a name="line162"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line163"></a>      &#39;The content moves out of the table in WEBKIT.&#39;);
<a name="line164"></a>
<a name="line165"></a>  if (goog.userAgent.IE) {
<a name="line166"></a>    // Not used since we bail out early for IE, but this is there so that
<a name="line167"></a>    // developers can easily reproduce IE error.
<a name="line168"></a>    goog.dom.Range.createFromNodeContents(
<a name="line169"></a>        document.getElementById(&#39;outerTr2&#39;)).select();
<a name="line170"></a>  } else {
<a name="line171"></a>    var selection = window.getSelection();
<a name="line172"></a>    if (selection.rangeCount &gt; 0) selection.removeAllRanges();
<a name="line173"></a>    var range = document.createRange();
<a name="line174"></a>    range.selectNode(document.getElementById(&#39;cell1&#39;));
<a name="line175"></a>    selection.addRange(range);
<a name="line176"></a>    range = document.createRange();
<a name="line177"></a>    range.selectNode(document.getElementById(&#39;cell2&#39;));
<a name="line178"></a>    selection.addRange(range);
<a name="line179"></a>  }
<a name="line180"></a>
<a name="line181"></a>  expectedFailures.run(function() {
<a name="line182"></a>    FORMATTER.removeFormatting_();
<a name="line183"></a>
<a name="line184"></a>    span = document.getElementById(&#39;outerTr2&#39;);
<a name="line185"></a>    assertEquals(&#39;Table data should not be removed&#39;,
<a name="line186"></a>        &#39;&lt;td id=&quot;cell1&quot;&gt;seven&lt;/td&gt;&lt;td id=&quot;cell2&quot;&gt;eight foo&lt;/td&gt;&#39;,
<a name="line187"></a>        span.innerHTML);
<a name="line188"></a>  });
<a name="line189"></a>}
<a name="line190"></a>
<a name="line191"></a>function testLinksAreNotRemoved() {
<a name="line192"></a>  expectedFailures.expectFailureFor(WEBKIT_BEFORE_CHROME_8,
<a name="line193"></a>      &#39;WebKit\&#39;s removeFormatting command removes links.&#39;);
<a name="line194"></a>
<a name="line195"></a>  var anchor;
<a name="line196"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line197"></a>  div.innerHTML = &#39;Foo&lt;span id=&quot;link&quot;&gt;Pre&lt;a href=&quot;http://www.google.com&quot;&gt;&#39; +
<a name="line198"></a>      &#39;Outside Span&lt;span style=&quot;font-size:15pt&quot;&gt;Inside Span&#39; +
<a name="line199"></a>      &#39;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&#39;;
<a name="line200"></a>
<a name="line201"></a>  anchor = document.getElementById(&#39;link&#39;);
<a name="line202"></a>  goog.dom.Range.createFromNodeContents(anchor).select();
<a name="line203"></a>
<a name="line204"></a>  expectedFailures.run(function() {
<a name="line205"></a>    FORMATTER.removeFormatting_();
<a name="line206"></a>    assertHTMLEquals(&#39;link should not be removed&#39;,
<a name="line207"></a>        &#39;FooPre&lt;a href=&quot;http://www.google.com/&quot;&gt;Outside SpanInside Span&lt;/a&gt;&#39;,
<a name="line208"></a>        div.innerHTML);
<a name="line209"></a>  });
<a name="line210"></a>}
<a name="line211"></a>
<a name="line212"></a>
<a name="line213"></a>/**
<a name="line214"></a> * A short formatting removal function for use with the RemoveFormatting
<a name="line215"></a> * plugin. Does enough that we can tell this function was run over the
<a name="line216"></a> * document.
<a name="line217"></a> * @param {string} text The HTML in from the document.
<a name="line218"></a> * @return {string} The &quot;cleaned&quot; HTML out.
<a name="line219"></a> */
<a name="line220"></a>function replacementFormattingFunc(text) {
<a name="line221"></a>  // Really basic so that we can just see this is executing.
<a name="line222"></a>  return text.replace(/Foo/gi, &#39;Bar&#39;).replace(/&lt;[\/]*span[^&gt;]*&gt;/gi, &#39;&#39;);
<a name="line223"></a>}
<a name="line224"></a>
<a name="line225"></a>function testAlternateRemoveFormattingFunction() {
<a name="line226"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line227"></a>  div.innerHTML = &#39;Start&lt;span id=&quot;remFormat&quot;&gt;Foo&lt;pre&gt;Bar&lt;/pre&gt;Baz&lt;/span&gt;&#39;;
<a name="line228"></a>
<a name="line229"></a>  FORMATTER.setRemoveFormattingFunc(replacementFormattingFunc);
<a name="line230"></a>  var area = document.getElementById(&#39;remFormat&#39;);
<a name="line231"></a>  goog.dom.Range.createFromNodeContents(area).select();
<a name="line232"></a>  FORMATTER.removeFormatting_();
<a name="line233"></a>  // Webkit will change all tags to non-formatted ones anyway.
<a name="line234"></a>  // Make sure &#39;Foo&#39; was changed to &#39;Bar&#39;
<a name="line235"></a>  if (WEBKIT_BEFORE_CHROME_8) {
<a name="line236"></a>    assertHTMLEquals(&#39;regular cleaner should not have run&#39;,
<a name="line237"></a>        &#39;StartBar&lt;br&gt;Bar&lt;br&gt;Baz&#39;,
<a name="line238"></a>        div.innerHTML);
<a name="line239"></a>  } else {
<a name="line240"></a>    assertHTMLEquals(&#39;regular cleaner should not have run&#39;,
<a name="line241"></a>        &#39;StartBar&lt;pre&gt;Bar&lt;/pre&gt;Baz&#39;,
<a name="line242"></a>        div.innerHTML);
<a name="line243"></a>  }
<a name="line244"></a>}
<a name="line245"></a>
<a name="line246"></a>function testGetValueForNode() {
<a name="line247"></a>  // Override getValueForNode to keep bold tags.
<a name="line248"></a>  var oldGetValue =
<a name="line249"></a>      goog.editor.plugins.RemoveFormatting.prototype.getValueForNode;
<a name="line250"></a>  goog.editor.plugins.RemoveFormatting.prototype.getValueForNode =
<a name="line251"></a>      function(node) {
<a name="line252"></a>    if (node.nodeName == goog.dom.TagName.B) {
<a name="line253"></a>      return &#39;&lt;b&gt;&#39; + this.removeFormattingWorker_(node.innerHTML) + &#39;&lt;/b&gt;&#39;;
<a name="line254"></a>    }
<a name="line255"></a>    return null;
<a name="line256"></a>  };
<a name="line257"></a>
<a name="line258"></a>  var html = FORMATTER.removeFormattingWorker_(&#39;&lt;div&gt;foo&lt;b&gt;bar&lt;/b&gt;&lt;/div&gt;&#39;);
<a name="line259"></a>  assertHTMLEquals(&#39;B tags should remain&#39;, &#39;foo&lt;b&gt;bar&lt;/b&gt;&#39;, html);
<a name="line260"></a>
<a name="line261"></a>  // Override getValueForNode to throw out bold tags, and their contents.
<a name="line262"></a>  goog.editor.plugins.RemoveFormatting.prototype.getValueForNode =
<a name="line263"></a>      function(node) {
<a name="line264"></a>    if (node.nodeName == goog.dom.TagName.B) {
<a name="line265"></a>      return &#39;&#39;;
<a name="line266"></a>    }
<a name="line267"></a>    return null;
<a name="line268"></a>  };
<a name="line269"></a>
<a name="line270"></a>  html = FORMATTER.removeFormattingWorker_(&#39;&lt;div&gt;foo&lt;b&gt;bar&lt;/b&gt;&lt;/div&gt;&#39;);
<a name="line271"></a>  assertHTMLEquals(&#39;B tag and its contents should be removed&#39;, &#39;foo&#39;, html);
<a name="line272"></a>
<a name="line273"></a>  FIELDMOCK.$verify();
<a name="line274"></a>  goog.editor.plugins.RemoveFormatting.prototype.getValueForNode =
<a name="line275"></a>      oldGetValue;
<a name="line276"></a>}
<a name="line277"></a>
<a name="line278"></a>function testRemoveFormattingAddsNoNbsps() {
<a name="line279"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line280"></a>  div.innerHTML = &#39;&quot;&lt;span id=&quot;toStrip&quot;&gt;Twin &lt;b&gt;Cinema&lt;/b&gt;&lt;/span&gt;&quot;&#39;;
<a name="line281"></a>
<a name="line282"></a>  var span = document.getElementById(&#39;toStrip&#39;);
<a name="line283"></a>  goog.dom.Range.createFromNodeContents(span).select();
<a name="line284"></a>
<a name="line285"></a>  FORMATTER.removeFormatting_();
<a name="line286"></a>
<a name="line287"></a>  assertEquals(&#39;Text should be the same, with no non-breaking spaces&#39;,
<a name="line288"></a>      &#39;&quot;Twin Cinema&quot;&#39;, div.innerHTML);
<a name="line289"></a>
<a name="line290"></a>  FIELDMOCK.$verify();
<a name="line291"></a>}
<a name="line292"></a>
<a name="line293"></a>
<a name="line294"></a>/**
<a name="line295"></a> * @bug 992795
<a name="line296"></a> */
<a name="line297"></a>function testRemoveFormattingNestedDivs() {
<a name="line298"></a>  var html = FORMATTER.removeFormattingWorker_(
<a name="line299"></a>      &#39;&lt;div&gt;1&lt;/div&gt;&lt;div&gt;&lt;div&gt;2&lt;/div&gt;&lt;/div&gt;&#39;);
<a name="line300"></a>
<a name="line301"></a>  goog.testing.dom.assertHtmlMatches(&#39;1&lt;br&gt;2&#39;, html);
<a name="line302"></a>}
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Test that when we perform remove formatting on an entire table,
<a name="line307"></a> * that the visual look is similiar to as if there was a table there.
<a name="line308"></a> */
<a name="line309"></a>function testRemoveFormattingForTableFormatting() {
<a name="line310"></a>  // We preserve the table formatting as much as possible.
<a name="line311"></a>  // Spaces separate TD&#39;s, &lt;br&gt;&#39;s separate TR&#39;s.
<a name="line312"></a>  // &lt;br&gt;&#39;s separate the start and end of a table.
<a name="line313"></a>  var html = &#39;&lt;table&gt;&lt;tr&gt;&lt;td&gt;cell00&lt;/td&gt;&lt;td&gt;cell01&lt;/td&gt;&lt;/tr&gt;&#39; +
<a name="line314"></a>      &#39;&lt;tr&gt;&lt;td&gt;cell10&lt;/td&gt;&lt;td&gt;cell11&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line315"></a>  html = FORMATTER.removeFormattingWorker_(html);
<a name="line316"></a>  assertHTMLEquals(&#39;&lt;br&gt;cell00 cell01&lt;br&gt;cell10 cell11&lt;br&gt;&#39;, html);
<a name="line317"></a>}
<a name="line318"></a>
<a name="line319"></a>
<a name="line320"></a>/**
<a name="line321"></a> * @bug 1319715
<a name="line322"></a> */
<a name="line323"></a>function testRemoveFormattingDoesNotShrinkSelection() {
<a name="line324"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line325"></a>  div.innerHTML = &#39;&lt;div&gt;l &lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;b&gt;a&lt;/b&gt;foo bar&lt;/div&gt;&#39;;
<a name="line326"></a>  var div2 = div.lastChild;
<a name="line327"></a>
<a name="line328"></a>  goog.dom.Range.createFromNodes(div2.firstChild, 0,
<a name="line329"></a>      div2.lastChild, 7).select();
<a name="line330"></a>
<a name="line331"></a>  FORMATTER.removeFormatting_();
<a name="line332"></a>
<a name="line333"></a>  var range = goog.dom.Range.createFromWindow();
<a name="line334"></a>  assertEquals(&#39;Correct text should be selected&#39;, &#39;afoo bar&#39;,
<a name="line335"></a>      range.getText());
<a name="line336"></a>
<a name="line337"></a>  // We have to trim out the leading BR in IE due to execCommand issues,
<a name="line338"></a>  // so it isn&#39;t sent off to the removeFormattingWorker.
<a name="line339"></a>  // Workaround for broken removeFormat in old webkit added an extra
<a name="line340"></a>  // &lt;br&gt; to the end of the html.
<a name="line341"></a>  var html = &#39;&lt;div&gt;l &lt;/div&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;afoo bar&#39; +
<a name="line342"></a>      (goog.editor.BrowserFeature.ADDS_NBSPS_IN_REMOVE_FORMAT ? &#39;&lt;br&gt;&#39; : &#39;&#39;);
<a name="line343"></a>
<a name="line344"></a>  goog.testing.dom.assertHtmlContentsMatch(html, div);
<a name="line345"></a>  FIELDMOCK.$verify();
<a name="line346"></a>}
<a name="line347"></a>
<a name="line348"></a>
<a name="line349"></a>/**
<a name="line350"></a> *  @bug 1447374
<a name="line351"></a> */
<a name="line352"></a>function testInsideListRemoveFormat() {
<a name="line353"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line354"></a>  div.innerHTML = &#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;li&gt;&lt;b&gt;two&lt;/b&gt;&lt;/li&gt;&lt;li&gt;three&lt;/li&gt;&lt;/ul&gt;&#39;;
<a name="line355"></a>
<a name="line356"></a>  var twoLi = div.firstChild.childNodes[1];
<a name="line357"></a>  goog.dom.Range.createFromNodeContents(twoLi).select();
<a name="line358"></a>
<a name="line359"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line360"></a>      &#39;IE adds the &quot;two&quot; to the &quot;three&quot; li, and leaves empty B tags.&#39;);
<a name="line361"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line362"></a>      &#39;WebKit leave the &quot;two&quot; orphaned outside of an li but &#39; +
<a name="line363"></a>      &#39;inside the ul (invalid HTML).&#39;);
<a name="line364"></a>
<a name="line365"></a>  expectedFailures.run(function() {
<a name="line366"></a>    FORMATTER.removeFormatting_();
<a name="line367"></a>    // Test that we split the list.
<a name="line368"></a>    assertHTMLEquals(&#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;two&lt;ul&gt;&lt;li&gt;three&lt;/li&gt;&lt;/ul&gt;&#39;,
<a name="line369"></a>        div.innerHTML);
<a name="line370"></a>    FIELDMOCK.$verify();
<a name="line371"></a>  });
<a name="line372"></a>}
<a name="line373"></a>
<a name="line374"></a>function testFullListRemoveFormat() {
<a name="line375"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line376"></a>  div.innerHTML =
<a name="line377"></a>      &#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;li&gt;&lt;b&gt;two&lt;/b&gt;&lt;/li&gt;&lt;li&gt;three&lt;/li&gt;&lt;/ul&gt;after&#39;;
<a name="line378"></a>
<a name="line379"></a>  goog.dom.Range.createFromNodeContents(div.firstChild).select();
<a name="line380"></a>
<a name="line381"></a>  //  Note: This may just be a createFromNodeContents issue, as
<a name="line382"></a>  //  I can&#39;t ever make this happen with real user selection.
<a name="line383"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line384"></a>      &#39;IE combines everything into a single LI and leaves the UL.&#39;);
<a name="line385"></a>
<a name="line386"></a>  expectedFailures.run(function() {
<a name="line387"></a>    FORMATTER.removeFormatting_();
<a name="line388"></a>    // Test that we completely remove the list.
<a name="line389"></a>    assertHTMLEquals(&#39;&lt;br&gt;one&lt;br&gt;two&lt;br&gt;threeafter&#39;,
<a name="line390"></a>        div.innerHTML);
<a name="line391"></a>    FIELDMOCK.$verify();
<a name="line392"></a>  });
<a name="line393"></a>}
<a name="line394"></a>
<a name="line395"></a>
<a name="line396"></a>/**
<a name="line397"></a> *  @bug 1440935
<a name="line398"></a> */
<a name="line399"></a>function testPartialListRemoveFormat() {
<a name="line400"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line401"></a>  div.innerHTML =
<a name="line402"></a>      &#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;li&gt;two&lt;/li&gt;&lt;li&gt;three&lt;/li&gt;&lt;/ul&gt;after&#39;;
<a name="line403"></a>
<a name="line404"></a>  // Select &quot;two three after&quot;.
<a name="line405"></a>  goog.dom.Range.createFromNodes(div.firstChild.childNodes[1], 0,
<a name="line406"></a>      div.lastChild, 5).select();
<a name="line407"></a>
<a name="line408"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line409"></a>      &#39;IE leaves behind an empty LI.&#39;);
<a name="line410"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line411"></a>      &#39;WebKit completely loses the &quot;one&quot;.&#39;);
<a name="line412"></a>
<a name="line413"></a>  expectedFailures.run(function() {
<a name="line414"></a>    FORMATTER.removeFormatting_();
<a name="line415"></a>    // Test that we leave the list start alone.
<a name="line416"></a>    assertHTMLEquals(&#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;two&lt;br&gt;threeafter&#39;,
<a name="line417"></a>        div.innerHTML);
<a name="line418"></a>    FIELDMOCK.$verify();
<a name="line419"></a>  });
<a name="line420"></a>}
<a name="line421"></a>
<a name="line422"></a>function testBasicRemoveFormatting() {
<a name="line423"></a>  // IE will clobber the editable div.
<a name="line424"></a>  // Note: I can&#39;t repro this using normal user selections.
<a name="line425"></a>  if (goog.userAgent.IE) {
<a name="line426"></a>    return;
<a name="line427"></a>  }
<a name="line428"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line429"></a>  div.innerHTML = &#39;&lt;b&gt;bold&lt;i&gt;italic&lt;/i&gt;&lt;/b&gt;&#39;;
<a name="line430"></a>
<a name="line431"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line432"></a>
<a name="line433"></a>  expectedFailures.expectFailureFor(
<a name="line434"></a>      goog.editor.BrowserFeature.ADDS_NBSPS_IN_REMOVE_FORMAT,
<a name="line435"></a>      &#39;The workaround for the nbsp bug adds an extra br at the end.&#39;);
<a name="line436"></a>
<a name="line437"></a>  expectedFailures.run(function() {
<a name="line438"></a>    FORMATTER.removeFormatting_();
<a name="line439"></a>    assertHTMLEquals(&#39;bolditalic&#39; + insertImageBoldGarbage,
<a name="line440"></a>        div.innerHTML);
<a name="line441"></a>    FIELDMOCK.$verify();
<a name="line442"></a>  });
<a name="line443"></a>}
<a name="line444"></a>
<a name="line445"></a>
<a name="line446"></a>/**
<a name="line447"></a> * @bug 1480260
<a name="line448"></a> */
<a name="line449"></a>function testPartialBasicRemoveFormatting() {
<a name="line450"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line451"></a>  div.innerHTML = &#39;&lt;b&gt;bold&lt;i&gt;italic&lt;/i&gt;&lt;/b&gt;&#39;;
<a name="line452"></a>
<a name="line453"></a>  goog.dom.Range.createFromNodes(div.firstChild.firstChild, 2,
<a name="line454"></a>      div.firstChild.lastChild.firstChild, 3).select();
<a name="line455"></a>
<a name="line456"></a>  expectedFailures.expectFailureFor(WEBKIT_BEFORE_CHROME_8,
<a name="line457"></a>      &#39;WebKit just gets this all wrong.  Everything stays bold and &#39; +
<a name="line458"></a>      &#39;&quot;lditalic&quot; gets italicised.&#39;);
<a name="line459"></a>
<a name="line460"></a>  expectedFailures.run(function() {
<a name="line461"></a>    FORMATTER.removeFormatting_();
<a name="line462"></a>    assertHTMLEquals(&#39;&lt;b&gt;bo&lt;/b&gt;ldita&lt;b&gt;&lt;i&gt;lic&lt;/i&gt;&lt;/b&gt;&#39;,
<a name="line463"></a>        div.innerHTML);
<a name="line464"></a>    FIELDMOCK.$verify();
<a name="line465"></a>  });
<a name="line466"></a>}
<a name="line467"></a>
<a name="line468"></a>
<a name="line469"></a>/**
<a name="line470"></a> * @bug 3075557
<a name="line471"></a> */
<a name="line472"></a>function testRemoveFormattingLinkedImageBorderZero() {
<a name="line473"></a>  var testHtml = &#39;&lt;a href=&quot;http://www.google.com/&quot;&gt;&#39; +
<a name="line474"></a>      &#39;&lt;img src=&quot;http://www.google.com/images/logo.gif&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&#39;;
<a name="line475"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line476"></a>  div.innerHTML = testHtml + controlHtml;
<a name="line477"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line478"></a>  FORMATTER.removeFormatting_();
<a name="line479"></a>
<a name="line480"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line481"></a>      &#39;WebKit removes the image entirely, see &#39; +
<a name="line482"></a>      &#39;https://bugs.webkit.org/show_bug.cgi?id=13125 .&#39;);
<a name="line483"></a>
<a name="line484"></a>  expectedFailures.run(function() {
<a name="line485"></a>    assertHTMLEquals(
<a name="line486"></a>        &#39;Image\&#39;s border=0 should not be removed during remove formatting&#39;,
<a name="line487"></a>        testHtml + controlCleanHtml, div.innerHTML);
<a name="line488"></a>    FIELDMOCK.$verify();
<a name="line489"></a>  });
<a name="line490"></a>}
<a name="line491"></a>
<a name="line492"></a>
<a name="line493"></a>/**
<a name="line494"></a> * @bug 3075557
<a name="line495"></a> */
<a name="line496"></a>function testRemoveFormattingLinkedImageBorderNonzero() {
<a name="line497"></a>  var testHtml = &#39;&lt;a href=&quot;http://www.google.com/&quot;&gt;&#39; +
<a name="line498"></a>      &#39;&lt;img src=&quot;http://www.google.com/images/logo.gif&quot; border=&quot;1&quot;&gt;&lt;/a&gt;&#39;;
<a name="line499"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line500"></a>  div.innerHTML = testHtml + controlHtml;
<a name="line501"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line502"></a>  FORMATTER.removeFormatting_();
<a name="line503"></a>
<a name="line504"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line505"></a>      &#39;WebKit removes the image entirely, see &#39; +
<a name="line506"></a>      &#39;https://bugs.webkit.org/show_bug.cgi?id=13125 .&#39;);
<a name="line507"></a>
<a name="line508"></a>  expectedFailures.run(function() {
<a name="line509"></a>    assertHTMLEquals(
<a name="line510"></a>        &#39;Image\&#39;s border should be removed during remove formatting&#39; +
<a name="line511"></a>        &#39; if non-zero&#39;,
<a name="line512"></a>        testHtml.replace(&#39; border=&quot;1&quot;&#39;, &#39;&#39;) + controlCleanHtml,
<a name="line513"></a>        div.innerHTML);
<a name="line514"></a>    FIELDMOCK.$verify();
<a name="line515"></a>  });
<a name="line516"></a>}
<a name="line517"></a>
<a name="line518"></a>
<a name="line519"></a>/**
<a name="line520"></a> * @bug 3075557
<a name="line521"></a> */
<a name="line522"></a>function testRemoveFormattingUnlinkedImage() {
<a name="line523"></a>  var testHtml =
<a name="line524"></a>      &#39;&lt;img src=&quot;http://www.google.com/images/logo.gif&quot; border=&quot;0&quot;&gt;&#39;;
<a name="line525"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line526"></a>  div.innerHTML = testHtml + controlHtml;
<a name="line527"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line528"></a>  FORMATTER.removeFormatting_();
<a name="line529"></a>
<a name="line530"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line531"></a>      &#39;WebKit removes the image entirely, see &#39; +
<a name="line532"></a>      &#39;https://bugs.webkit.org/show_bug.cgi?id=13125 .&#39;);
<a name="line533"></a>
<a name="line534"></a>  expectedFailures.run(function() {
<a name="line535"></a>    assertHTMLEquals(
<a name="line536"></a>        &#39;Image\&#39;s border=0 should not be removed during remove formatting&#39; +
<a name="line537"></a>        &#39; even if not wrapped by a link&#39;,
<a name="line538"></a>        testHtml + controlCleanHtml, div.innerHTML);
<a name="line539"></a>    FIELDMOCK.$verify();
<a name="line540"></a>  });
<a name="line541"></a>}
<a name="line542"></a>
<a name="line543"></a>
<a name="line544"></a>/**
<a name="line545"></a> * @bug 3075557
<a name="line546"></a> */
<a name="line547"></a>function testRemoveFormattingLinkedImageDeep() {
<a name="line548"></a>  var testHtml = &#39;&lt;a href=&quot;http://www.google.com/&quot;&gt;&lt;b&gt;hello&#39; +
<a name="line549"></a>      &#39;&lt;img src=&quot;http://www.google.com/images/logo.gif&quot; border=&quot;0&quot;&gt;&#39; +
<a name="line550"></a>      &#39;world&lt;/b&gt;&lt;/a&gt;&#39;;
<a name="line551"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line552"></a>  div.innerHTML = testHtml + controlHtml;
<a name="line553"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line554"></a>  FORMATTER.removeFormatting_();
<a name="line555"></a>
<a name="line556"></a>  expectedFailures.expectFailureFor(WEBKIT_BEFORE_CHROME_8,
<a name="line557"></a>      &#39;WebKit removes the image entirely, see &#39; +
<a name="line558"></a>      &#39;https://bugs.webkit.org/show_bug.cgi?id=13125 .&#39;);
<a name="line559"></a>
<a name="line560"></a>  expectedFailures.run(function() {
<a name="line561"></a>    assertHTMLEquals(
<a name="line562"></a>        &#39;Image\&#39;s border=0 should not be removed during remove formatting&#39; +
<a name="line563"></a>        &#39; even if deep inside anchor tag&#39;,
<a name="line564"></a>        testHtml.replace(/&lt;\/?b&gt;/g, &#39;&#39;) +
<a name="line565"></a>        controlCleanHtml + insertImageBoldGarbage,
<a name="line566"></a>        div.innerHTML);
<a name="line567"></a>    FIELDMOCK.$verify();
<a name="line568"></a>  });
<a name="line569"></a>}
<a name="line570"></a>
<a name="line571"></a>function testFullTableRemoveFormatting() {
<a name="line572"></a>  // Something goes horrible wrong in case 1 below.  It was crashing all
<a name="line573"></a>  // WebKit browsers, and now seems to be giving errors as it is trying
<a name="line574"></a>  // to perform remove formatting on the little expected failures window
<a name="line575"></a>  // instead of the dom we select.  WTF.  Since I&#39;m gutting this code,
<a name="line576"></a>  // I&#39;m not going to look into this anymore right now.  For what its worth,
<a name="line577"></a>  // I can&#39;t repro any issues in standalone TrogEdit.
<a name="line578"></a>  if (goog.userAgent.WEBKIT) {
<a name="line579"></a>    return;
<a name="line580"></a>  }
<a name="line581"></a>
<a name="line582"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line583"></a>
<a name="line584"></a>  // WebKit has an extra BR in case 2.
<a name="line585"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line586"></a>      &#39;IE clobbers the editable node in case 2 (can\&#39;t repro with real &#39; +
<a name="line587"></a>      &#39;user selections). IE doesn\&#39;t remove the table in case 1.&#39;);
<a name="line588"></a>
<a name="line589"></a>  expectedFailures.run(function() {
<a name="line590"></a>
<a name="line591"></a>    // When a full table is selected, we remove it completely.
<a name="line592"></a>    div.innerHTML = &#39;foo&lt;table&gt;&lt;tr&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;baz1&#39;;
<a name="line593"></a>    goog.dom.Range.createFromNodeContents(div.childNodes[1]).select();
<a name="line594"></a>    FORMATTER.removeFormatting_();
<a name="line595"></a>    assertHTMLEquals(&#39;foo&lt;br&gt;bar&lt;br&gt;baz1&#39;, div.innerHTML);
<a name="line596"></a>    FIELDMOCK.$verify();
<a name="line597"></a>
<a name="line598"></a>    // Remove the full table when it is selected with additional
<a name="line599"></a>    // contents too.
<a name="line600"></a>    div.innerHTML = &#39;foo&lt;table&gt;&lt;tr&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;baz2&#39;;
<a name="line601"></a>    goog.dom.Range.createFromNodes(div.firstChild, 0,
<a name="line602"></a>        div.lastChild, 1).select();
<a name="line603"></a>    FORMATTER.removeFormatting_();
<a name="line604"></a>    assertHTMLEquals(&#39;foo&lt;br&gt;bar&lt;br&gt;baz2&#39;, div.innerHTML);
<a name="line605"></a>    FIELDMOCK.$verify();
<a name="line606"></a>
<a name="line607"></a>    // We should still remove the table, even if the selection is inside the
<a name="line608"></a>    // table and it is fully selected.
<a name="line609"></a>    div.innerHTML = &#39;foo&lt;table&gt;&lt;tr&gt;&lt;td id=\&#39;td\&#39;&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;baz3&#39;;
<a name="line610"></a>    goog.dom.Range.createFromNodeContents(
<a name="line611"></a>        goog.dom.getElement(&#39;td&#39;).firstChild).select();
<a name="line612"></a>    FORMATTER.removeFormatting_();
<a name="line613"></a>    assertHTMLEquals(&#39;foo&lt;br&gt;bar&lt;br&gt;baz3&#39;, div.innerHTML);
<a name="line614"></a>    FIELDMOCK.$verify();
<a name="line615"></a>  });
<a name="line616"></a>}
<a name="line617"></a>
<a name="line618"></a>function testInsideTableRemoveFormatting() {
<a name="line619"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line620"></a>  div.innerHTML =
<a name="line621"></a>      &#39;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;b id=&quot;b&quot;&gt;foo&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ba&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line622"></a>
<a name="line623"></a>  goog.dom.Range.createFromNodeContents(goog.dom.getElement(&#39;b&#39;)).select();
<a name="line624"></a>
<a name="line625"></a>  // Webkit adds some apple style span crap during execCommand(&quot;removeFormat&quot;)
<a name="line626"></a>  // Our workaround for the nbsp bug removes these, but causes worse problems.
<a name="line627"></a>  // See bugs.webkit.org/show_bug.cgi?id=29164 for more details.
<a name="line628"></a>  expectedFailures.expectFailureFor(
<a name="line629"></a>      WEBKIT_BEFORE_CHROME_8 &amp;&amp;
<a name="line630"></a>      !goog.editor.BrowserFeature.ADDS_NBSPS_IN_REMOVE_FORMAT,
<a name="line631"></a>      &#39;Extra apple-style-spans&#39;);
<a name="line632"></a>
<a name="line633"></a>  expectedFailures.run(function() {
<a name="line634"></a>    FORMATTER.removeFormatting_();
<a name="line635"></a>
<a name="line636"></a>    // Only remove styling from inside tables.
<a name="line637"></a>    assertHTMLEquals(
<a name="line638"></a>        &#39;&lt;table&gt;&lt;tr&gt;&lt;td&gt;foo&#39; + insertImageBoldGarbage +
<a name="line639"></a>        &#39;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ba&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;,
<a name="line640"></a>        div.innerHTML);
<a name="line641"></a>    FIELDMOCK.$verify();
<a name="line642"></a>  });
<a name="line643"></a>
<a name="line644"></a>}
<a name="line645"></a>
<a name="line646"></a>function testPartialTableRemoveFormatting() {
<a name="line647"></a>  if (goog.userAgent.IE) {
<a name="line648"></a>    // IE returns an &quot;unspecified error&quot; which seems to be beyond
<a name="line649"></a>    // ExpectedFailures&#39; ability to catch.
<a name="line650"></a>    return;
<a name="line651"></a>  }
<a name="line652"></a>
<a name="line653"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line654"></a>  div.innerHTML = &#39;bar&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;b id=&quot;b&quot;&gt;foo&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&#39; +
<a name="line655"></a>                  &#39;&lt;tr&gt;&lt;td&gt;&lt;i&gt;banana&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div id=&quot;baz&quot;&gt;&#39; +
<a name="line656"></a>                  &#39;baz&lt;/div&gt;&#39;;
<a name="line657"></a>
<a name="line658"></a>  // Select from the &quot;oo&quot; inside the b tag to the end of &quot;baz&quot;.
<a name="line659"></a>  goog.dom.Range.createFromNodes(goog.dom.getElement(&#39;b&#39;).firstChild, 1,
<a name="line660"></a>      goog.dom.getElement(&#39;baz&#39;).firstChild, 3).select();
<a name="line661"></a>
<a name="line662"></a>  // All browsers currently clobber the table cells that are selected.
<a name="line663"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
<a name="line664"></a>
<a name="line665"></a>  expectedFailures.run(function() {
<a name="line666"></a>    FORMATTER.removeFormatting_();
<a name="line667"></a>    // Only remove styling from inside tables.
<a name="line668"></a>    assertHTMLEquals(&#39;bar&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;b id=&quot;b&quot;&gt;f&lt;/b&gt;oo&lt;/td&gt;&lt;/tr&gt;&#39; +
<a name="line669"></a>                     &#39;&lt;tr&gt;&lt;td&gt;banana&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;baz&#39;, div.innerHTML);
<a name="line670"></a>    FIELDMOCK.$verify();
<a name="line671"></a>  });
<a name="line672"></a>}
<a name="line673"></a>
<a name="line674"></a>// Runs tests knowing some browsers will fail, because the new
<a name="line675"></a>// table functionality hasn&#39;t been implemented in them yet.
<a name="line676"></a>function runExpectingFailuresForUnimplementedBrowsers(func) {
<a name="line677"></a>  if (goog.userAgent.IE) {
<a name="line678"></a>    // IE returns an &quot;unspecified error&quot; which seems to be beyond
<a name="line679"></a>    // ExpectedFailures&#39; ability to catch.
<a name="line680"></a>    return;
<a name="line681"></a>  }
<a name="line682"></a>
<a name="line683"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line684"></a>      &#39;Proper behavior not yet implemented for IE.&#39;);
<a name="line685"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line686"></a>      &#39;Proper behavior not yet implemented for WebKit.&#39;);
<a name="line687"></a>
<a name="line688"></a>  expectedFailures.run(func);
<a name="line689"></a>}
<a name="line690"></a>
<a name="line691"></a>
<a name="line692"></a>function testTwoTablesSelectedFullyRemoveFormatting() {
<a name="line693"></a>  runExpectingFailuresForUnimplementedBrowsers(function() {
<a name="line694"></a>    var div = document.getElementById(&#39;html&#39;);
<a name="line695"></a>    // When two tables are fully selected, we remove them completely.
<a name="line696"></a>    div.innerHTML = &#39;&lt;table&gt;&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39; +
<a name="line697"></a>                    &#39;&lt;table&gt;&lt;tr&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line698"></a>    goog.dom.Range.createFromNodes(div.firstChild, 0,
<a name="line699"></a>        div.lastChild, 1).select();
<a name="line700"></a>    FORMATTER.removeFormatting_();
<a name="line701"></a>    assertHTMLEquals(&#39;&lt;br&gt;foo&lt;br&gt;&lt;br&gt;bar&lt;br&gt;&#39;, div.innerHTML);
<a name="line702"></a>    FIELDMOCK.$verify();
<a name="line703"></a>  });
<a name="line704"></a>}
<a name="line705"></a>
<a name="line706"></a>function testTwoTablesSelectedFullyInsideRemoveFormatting() {
<a name="line707"></a>  if (goog.userAgent.WEBKIT) {
<a name="line708"></a>    // Something goes very wrong here, but it did before
<a name="line709"></a>    // Julie started writing v2.  Will address when converting
<a name="line710"></a>    // safari to v2.
<a name="line711"></a>    return;
<a name="line712"></a>  }
<a name="line713"></a>
<a name="line714"></a>  runExpectingFailuresForUnimplementedBrowsers(function() {
<a name="line715"></a>    var div = document.getElementById(&#39;html&#39;);
<a name="line716"></a>    // When two tables are selected from inside but fully,
<a name="line717"></a>    // also remove them completely.
<a name="line718"></a>    div.innerHTML = &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td1&quot;&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39; +
<a name="line719"></a>                    &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td2&quot;&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line720"></a>    goog.dom.Range.createFromNodes(goog.dom.getElement(&#39;td1&#39;).firstChild, 0,
<a name="line721"></a>        goog.dom.getElement(&#39;td2&#39;).firstChild, 3).select();
<a name="line722"></a>    FORMATTER.removeFormatting_();
<a name="line723"></a>    assertHTMLEquals(&#39;&lt;br&gt;foo&lt;br&gt;&lt;br&gt;bar&lt;br&gt;&#39;, div.innerHTML);
<a name="line724"></a>    FIELDMOCK.$verify();
<a name="line725"></a>  });
<a name="line726"></a>}
<a name="line727"></a>
<a name="line728"></a>function testTwoTablesSelectedFullyAndPartiallyRemoveFormatting() {
<a name="line729"></a>  runExpectingFailuresForUnimplementedBrowsers(function() {
<a name="line730"></a>    var div = document.getElementById(&#39;html&#39;);
<a name="line731"></a>    // Two tables selected, one fully, one partially. Remove
<a name="line732"></a>    // only the fully selected one and remove styles only from
<a name="line733"></a>    // partially selected one.
<a name="line734"></a>    div.innerHTML = &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td1&quot;&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39; +
<a name="line735"></a>                    &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td2&quot;&gt;&lt;b&gt;bar&lt;b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line736"></a>    goog.dom.Range.createFromNodes(goog.dom.getElement(&#39;td1&#39;).firstChild, 0,
<a name="line737"></a>        goog.dom.getElement(&#39;td2&#39;).firstChild.firstChild, 2).select();
<a name="line738"></a>    FORMATTER.removeFormatting_();
<a name="line739"></a>    assertHTMLEquals(&#39;&lt;br&gt;foo&lt;br&gt;&#39; +
<a name="line740"></a>                     &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td2&quot;&gt;ba&lt;b&gt;r&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;,
<a name="line741"></a>        div.innerHTML);
<a name="line742"></a>    FIELDMOCK.$verify();
<a name="line743"></a>  });
<a name="line744"></a>}
<a name="line745"></a>
<a name="line746"></a>function testTwoTablesSelectedPartiallyRemoveFormatting() {
<a name="line747"></a>  runExpectingFailuresForUnimplementedBrowsers(function() {
<a name="line748"></a>    var div = document.getElementById(&#39;html&#39;);
<a name="line749"></a>    // Two tables selected, both partially.  Don&#39;t remove tables,
<a name="line750"></a>    // but remove styles.
<a name="line751"></a>    div.innerHTML = &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td1&quot;&gt;f&lt;i&gt;o&lt;/i&gt;o&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39; +
<a name="line752"></a>                    &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td2&quot;&gt;b&lt;b&gt;a&lt;/b&gt;r&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;;
<a name="line753"></a>    goog.dom.Range.createFromNodes(goog.dom.getElement(&#39;td1&#39;).firstChild, 1,
<a name="line754"></a>        goog.dom.getElement(&#39;td2&#39;).childNodes[1], 1).select();
<a name="line755"></a>    FORMATTER.removeFormatting_();
<a name="line756"></a>    assertHTMLEquals(&#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td1&quot;&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39; +
<a name="line757"></a>                     &#39;&lt;table&gt;&lt;tr&gt;&lt;td id=&quot;td2&quot;&gt;bar&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;,
<a name="line758"></a>                     div.innerHTML);
<a name="line759"></a>    FIELDMOCK.$verify();
<a name="line760"></a>  });
<a name="line761"></a>}
<a name="line762"></a>
<a name="line763"></a>
<a name="line764"></a>/**
<a name="line765"></a> * Test a random snippet from Google News (Google News has complicated
<a name="line766"></a> * dom structure, including tables, links, images, etc).
<a name="line767"></a> */
<a name="line768"></a>function testRandomGoogleNewsSnippetRemoveFormatting() {
<a name="line769"></a>  if (goog.userAgent.IE) {
<a name="line770"></a>    // IE returns an &quot;unspecified error&quot; which seems to be beyond
<a name="line771"></a>    // ExpectedFailures&#39; ability to catch.
<a name="line772"></a>    return;
<a name="line773"></a>  }
<a name="line774"></a>
<a name="line775"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line776"></a>  div.innerHTML =
<a name="line777"></a>      &#39;&lt;font size=&quot;-3&quot;&gt;&lt;br&gt;&lt;/font&gt;&lt;table align=&quot;right&quot; border=&quot;0&quot; &#39; +
<a name="line778"></a>      &#39;cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;padding-left:&#39; +
<a name="line779"></a>      &#39;6px;&quot; valign=&quot;top&quot; width=&quot;80&quot; align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.wash&#39; +
<a name="line780"></a>      &#39;ingtonpost.com/wp-dyn/content/article/2008/11/11/AR2008111101090.htm&#39; +
<a name="line781"></a>      &#39;l&quot; + id=&quot;s-skHRvWH7ryqkcA4caGv0QQ:u-AFQjCNG3vx1HJOxKxMQPzCvYOVRE0JUDe&#39; +
<a name="line782"></a>      &#39;Q:r-1-0i_1268233361_6_H0_MH20_PL60&quot;&gt;&lt;img src=&quot;http://news.google.com/&#39; +
<a name="line783"></a>      &#39;news?imgefp=4LFiNNP62TgJ&amp;amp;imgurl=media3.washingtonpost.com/wp-dyn/&#39; +
<a name="line784"></a>      &#39;content/photo/2008/11/11/PH2008111101091.jpg&quot; alt=&quot;&quot; width=&quot;60&quot; &#39; +
<a name="line785"></a>      &#39;border=&quot;1&quot; height=&quot;80&quot;&gt;&lt;br&gt;&lt;font size=&quot;-2&quot;&gt;Washington Post&lt;/font&gt;&lt;/a&gt;&#39; +
<a name="line786"></a>      &#39;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;a href=&quot;http://www.nme.com/news/britney-&#39; +
<a name="line787"></a>      &#39;spears/40995&quot; id=&quot;s-xZUO-t0c1IpsVjyJj0rgxw:u-AFQjCNEZAMQCseEW6uTgXI&#39; +
<a name="line788"></a>      &#39;iPvAMHe_0B4A:r-1-0_1268233361_6_H0_MH20_PL60&quot;&gt;&lt;b&gt;Britney\&#39;s son &#39; +
<a name="line789"></a>      &#39;released from hospital&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;font size=&quot;-1&quot;&gt;&lt;b&gt;&lt;font color=&#39; +
<a name="line790"></a>      &#39;&quot;#6f6f6f&quot;&gt;NME.com&amp;nbsp;-&lt;/font&gt; &lt;nobr&gt;53 minutes ago&lt;/nobr&gt;&lt;/b&gt;&#39; +
<a name="line791"></a>      &#39;&lt;/font&gt;&lt;br&gt;&lt;font size=&quot;-1&quot;&gt;Britney Spears? youngest son Jayden James &#39; +
<a name="line792"></a>      &#39;has been released from hospital, having been admitted on Sunday after&#39; +
<a name="line793"></a>      &#39; suffering a severe reaction to something he ingested.&lt;/font&gt;&lt;br&gt;&lt;fon&#39; +
<a name="line794"></a>      &#39;tsize=&quot;-1&quot;&gt;&lt;a href=&quot;http://www.celebrity-gossip.net/celebrities/holly&#39; +
<a name="line795"></a>      &#39;wood/britney-and-jamie-lynn-spears-alligator-alley-208944/&quot; id=&quot;s-nM&#39; +
<a name="line796"></a>      &#39;PzHclcMG0J2WZkw9gnVQ:u-AFQjCNHal08usOQ5e5CAQsck2yGsTYeGVQ&quot;&gt;Britney &#39; +
<a name="line797"></a>      &#39;and Jamie Lynn Spears: Alligator Alley!&lt;/a&gt; &lt;font size=&quot;-1&quot; color=&#39; +
<a name="line798"></a>      &#39;&quot;#6f6f6f&quot;&gt;&lt;nobr&gt;The Gossip Girls&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=&#39; +
<a name="line799"></a>      &#39;&quot;-1&quot;&gt;&lt;a href=&quot;http://foodconsumer.org/7777/8888/Other_N_ews_51/111101&#39; +
<a name="line800"></a>      &#39;362008_Allergy_incident_could_spell_custody_trouble_for_Britney_Spear&#39; +
<a name="line801"></a>      &#39;s.shtml&quot; id=&quot;s-2lMNDY4joOprVvkkY_b-6A:u-AFQjCNGAeFNutMEbSg5zAvrh5reBF&#39; +
<a name="line802"></a>      &#39;lqUmA&quot;&gt;Allergy incident could spell trouble for Britney Spears&lt;/a&gt; &#39; +
<a name="line803"></a>      &#39;&lt;font size=&quot;-1&quot; color=&quot;#6f6f6f&quot;&gt;&lt;nobr&gt;Food Consumer&lt;/nobr&gt;&lt;/font&gt;&#39; +
<a name="line804"></a>      &#39;&lt;/font&gt;&lt;br&gt;&lt;font class=&quot;p&quot; size=&quot;-1&quot;&gt;&lt;a href=&quot;http://www.people.com/&#39; +
<a name="line805"></a>      &#39;people/article/0,,20239458,00.html&quot; id=&quot;s-x9thwVUYVET0ZJOnkkcsjw:u-A&#39; +
<a name="line806"></a>      &#39;FQjCNE99eijVIrezr9AFRjLkmo5j_Jr7A&quot;&gt;&lt;nobr&gt;People Magazine&lt;/nobr&gt;&lt;/a&gt;&amp;nb&#39; +
<a name="line807"></a>      &#39;sp;- &lt;a href=&quot;http://www.eonline.com/uberblog/b68226_hospital_run_cou&#39; +
<a name="line808"></a>      &#39;ld_cost_britney_custody.html&quot; id=&quot;s-kYt5LHDhlDnhUL9kRLuuwA:u-AFQjCNF8&#39; +
<a name="line809"></a>      &#39;8eOy2utriYuF0icNrZQPzwK8gg&quot;&gt;&lt;nobr&gt;E! Online&lt;/nobr&gt;&lt;/a&gt;&amp;nbsp;- &lt;a href&#39; +
<a name="line810"></a>      &#39;=&quot;http://justjared.buzznet.com/2008/11/11/britney-spears-alligator-fa&#39; +
<a name="line811"></a>      &#39;rm/&quot; id=&quot;s--VDy1fyacNvaRo_aXb02Dw:u-AFQjCNEn0Rz3wg0PMwDdzKTDug-9k5W6y&#39; +
<a name="line812"></a>      &#39;g&quot;&gt;&lt;nobr&gt;Just Jared&lt;/nobr&gt;&lt;/a&gt;&amp;nbsp;- &lt;a href=&quot;http://www.efluxmedia.&#39; +
<a name="line813"></a>      &#39;com/news_Britney_Spears_Son_Released_from_Hospital_28696.html&quot; id=&quot;s-&#39; +
<a name="line814"></a>      &#39;8oX6hVDe4Qbcl1x5Rua_EA:u-AFQjCNEpn3nOHA8EB0pxJAPf6diOicMRDg&quot;&gt;&lt;nobr&gt;eF&#39; +
<a name="line815"></a>      &#39;luxMedia&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&lt;br&gt;&lt;font class=&quot;p&quot; size=&quot;-1&quot;&gt;&lt;a class=&quot;p&quot; &#39; +
<a name="line816"></a>      &#39;href=&quot;http://news.google.com/news?ncl=1268233361&amp;amp;hl=en&quot;&gt;&lt;nobr&gt;&lt;b&gt;&#39; +
<a name="line817"></a>      &#39;all 950 news articles&amp;nbsp;?&lt;/b&gt;&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&#39;;
<a name="line818"></a>  // Select it all.
<a name="line819"></a>  goog.dom.Range.createFromNodeContents(div).select();
<a name="line820"></a>
<a name="line821"></a>  expectedFailures.expectFailureFor(WEBKIT_BEFORE_CHROME_8,
<a name="line822"></a>      &#39;WebKit barfs apple-style-spans all over the place, and removes links.&#39;);
<a name="line823"></a>
<a name="line824"></a>  expectedFailures.run(function() {
<a name="line825"></a>    FORMATTER.removeFormatting_();
<a name="line826"></a>    // Leave links and images alone, remove all other formatting.
<a name="line827"></a>    assertHTMLEquals(&#39;&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://www.washingtonpost.com/wp-dyn/&#39; +
<a name="line828"></a>        &#39;content/article/2008/11/11/AR2008111101090.html&quot;&gt;&lt;img src=&quot;http://n&#39; +
<a name="line829"></a>        &#39;ews.google.com/news?imgefp=4LFiNNP62TgJ&amp;amp;imgurl=media3.washingto&#39; +
<a name="line830"></a>        &#39;npost.com/wp-dyn/content/photo/2008/11/11/PH2008111101091.jpg&quot;&gt;&lt;br&gt;&#39; +
<a name="line831"></a>        &#39;Washington Post&lt;/a&gt;&lt;br&gt;&lt;a href=&quot;http://www.nme.com/news/britney-spe&#39; +
<a name="line832"></a>        &#39;ars/40995&quot;&gt;Britney\&#39;s son released from hospital&lt;/a&gt;&lt;br&gt;NME.com - 5&#39; +
<a name="line833"></a>        &#39;3 minutes ago&lt;br&gt;Britney Spears? youngest son Jayden James has been&#39; +
<a name="line834"></a>        &#39; released from hospital, having been admitted on Sunday after suffe&#39; +
<a name="line835"></a>        &#39;ring a severe reaction to something he ingested.&lt;br&gt;&lt;a href=&quot;http:/&#39; +
<a name="line836"></a>        &#39;/www.celebrity-gossip.net/celebrities/hollywood/britney-and-jamie-l&#39; +
<a name="line837"></a>        &#39;ynn-spears-alligator-alley-208944/&quot;&gt;Britney and Jamie Lynn Spears: &#39; +
<a name="line838"></a>        &#39;Alligator Alley!&lt;/a&gt; The Gossip Girls&lt;br&gt;&lt;a href=&quot;http://foodconsum&#39; +
<a name="line839"></a>        &#39;er.org/7777/8888/Other_N_ews_51/111101362008_Allergy_incident_could&#39; +
<a name="line840"></a>        &#39;_spell_custody_trouble_for_Britney_Spears.shtml&quot;&gt;Allergy incident c&#39; +
<a name="line841"></a>        &#39;ould spell trouble for Britney Spears&lt;/a&gt; Food Consumer&lt;br&gt;&lt;a href=&#39; +
<a name="line842"></a>        &#39;&quot;http://www.people.com/people/article/0,,20239458,00.html&quot;&gt;People M&#39; +
<a name="line843"></a>        &#39;agazine&lt;/a&gt; - &lt;a href=&quot;http://www.eonline.com/uberblog/b68226_hospi&#39; +
<a name="line844"></a>        &#39;tal_run_could_cost_britney_custody.html&quot;&gt;E! Online&lt;/a&gt; - &lt;a href=&quot;h&#39; +
<a name="line845"></a>        &#39;ttp://justjared.buzznet.com/2008/11/11/britney-spears-alligator-far&#39; +
<a name="line846"></a>        &#39;m/&quot;&gt;Just Jared&lt;/a&gt; - &lt;a href=&quot;http://www.efluxmedia.com/news_Britne&#39; +
<a name="line847"></a>        &#39;y_Spears_Son_Released_from_Hospital_28696.html&quot;&gt;eFluxMedia&lt;/a&gt;&lt;br&gt;&lt;&#39; +
<a name="line848"></a>        &#39;a href=&quot;http://news.google.com/news?ncl=1268233361&amp;amp;hl=en&quot;&gt;all 9&#39; +
<a name="line849"></a>        &#39;50 news articles ?&lt;/a&gt;&#39; +
<a name="line850"></a>        insertImageFontGarbage, div.innerHTML);
<a name="line851"></a>    FIELDMOCK.$verify();
<a name="line852"></a>  });
<a name="line853"></a>}
<a name="line854"></a>
<a name="line855"></a>function testRangeDelimitedByRanges() {
<a name="line856"></a>  var abcde = goog.dom.getElement(&#39;abcde&#39;).firstChild;
<a name="line857"></a>  var start = goog.dom.Range.createFromNodes(abcde, 1, abcde, 2);
<a name="line858"></a>  var end = goog.dom.Range.createFromNodes(abcde, 3, abcde, 4);
<a name="line859"></a>
<a name="line860"></a>  goog.testing.dom.assertRangeEquals(abcde, 1, abcde, 4,
<a name="line861"></a>      goog.editor.plugins.RemoveFormatting.createRangeDelimitedByRanges_(
<a name="line862"></a>          start, end));
<a name="line863"></a>}
<a name="line864"></a>
<a name="line865"></a>function testGetTableAncestor() {
<a name="line866"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line867"></a>
<a name="line868"></a>  div.innerHTML = &#39;foo&lt;table&gt;&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;bar&#39;;
<a name="line869"></a>  assertTrue(&#39;Full table is in table&#39;,
<a name="line870"></a>      !!FORMATTER.getTableAncestor_(div.childNodes[1]));
<a name="line871"></a>
<a name="line872"></a>  assertFalse(&#39;Outside of table&#39;,
<a name="line873"></a>      !!FORMATTER.getTableAncestor_(div.firstChild));
<a name="line874"></a>
<a name="line875"></a>  assertTrue(&#39;Table cell is in table&#39;,
<a name="line876"></a>      !!FORMATTER.getTableAncestor_(
<a name="line877"></a>          div.childNodes[1].firstChild.firstChild.firstChild));
<a name="line878"></a>
<a name="line879"></a>  div.innerHTML = &#39;foo&#39;;
<a name="line880"></a>  assertNull(&#39;No table inside field.&#39;,
<a name="line881"></a>      FORMATTER.getTableAncestor_(div.childNodes[0]));
<a name="line882"></a>}
<a name="line883"></a>
<a name="line884"></a>
<a name="line885"></a>/**
<a name="line886"></a> * @bug 1272905
<a name="line887"></a> */
<a name="line888"></a>function testHardReturnsInHeadersPreserved() {
<a name="line889"></a>  var div = document.getElementById(&#39;html&#39;);
<a name="line890"></a>  div.innerHTML = &#39;&lt;h1&gt;abcd&lt;/h1&gt;&lt;h2&gt;efgh&lt;/h2&gt;&lt;h3&gt;ijkl&lt;/h3&gt;&#39;;
<a name="line891"></a>
<a name="line892"></a>  // Select efgh.
<a name="line893"></a>  goog.dom.Range.createFromNodeContents(div.childNodes[1]).select();
<a name="line894"></a>  FORMATTER.removeFormatting_();
<a name="line895"></a>
<a name="line896"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line897"></a>      &#39;Proper behavior not yet implemented for IE.&#39;);
<a name="line898"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line899"></a>      &#39;Proper behavior not yet implemented for WebKit.&#39;);
<a name="line900"></a>  expectedFailures.run(function() {
<a name="line901"></a>    assertHTMLEquals(&#39;&lt;h1&gt;abcd&lt;/h1&gt;&lt;br&gt;efgh&lt;h3&gt;ijkl&lt;/h3&gt;&#39;, div.innerHTML);
<a name="line902"></a>  });
<a name="line903"></a>
<a name="line904"></a>  // Select ijkl.
<a name="line905"></a>  goog.dom.Range.createFromNodeContents(div.lastChild).select();
<a name="line906"></a>  FORMATTER.removeFormatting_();
<a name="line907"></a>
<a name="line908"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line909"></a>      &#39;Proper behavior not yet implemented for IE.&#39;);
<a name="line910"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line911"></a>      &#39;Proper behavior not yet implemented for WebKit.&#39;);
<a name="line912"></a>  expectedFailures.run(function() {
<a name="line913"></a>    assertHTMLEquals(&#39;&lt;h1&gt;abcd&lt;/h1&gt;&lt;br&gt;efgh&lt;br&gt;ijkl&#39;, div.innerHTML);
<a name="line914"></a>  });
<a name="line915"></a>
<a name="line916"></a>  // Select abcd.
<a name="line917"></a>  goog.dom.Range.createFromNodeContents(div.firstChild).select();
<a name="line918"></a>  FORMATTER.removeFormatting_();
<a name="line919"></a>
<a name="line920"></a>  expectedFailures.expectFailureFor(goog.userAgent.IE,
<a name="line921"></a>      &#39;Proper behavior not yet implemented for IE.&#39;);
<a name="line922"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT,
<a name="line923"></a>      &#39;Proper behavior not yet implemented for WebKit.&#39;);
<a name="line924"></a>  expectedFailures.run(function() {
<a name="line925"></a>    assertHTMLEquals(&#39;&lt;br&gt;abcd&lt;br&gt;efgh&lt;br&gt;ijkl&#39;, div.innerHTML);
<a name="line926"></a>  });
<a name="line927"></a>}
<a name="line928"></a>
<a name="line929"></a>function testKeyboardShortcut_space() {
<a name="line930"></a>  FIELDMOCK.$reset();
<a name="line931"></a>
<a name="line932"></a>  FIELDMOCK.execCommand(
<a name="line933"></a>      goog.editor.plugins.RemoveFormatting.REMOVE_FORMATTING_COMMAND);
<a name="line934"></a>
<a name="line935"></a>  FIELDMOCK.$replay();
<a name="line936"></a>
<a name="line937"></a>  var e = {};
<a name="line938"></a>  var key = &#39; &#39;;
<a name="line939"></a>  var result = FORMATTER.handleKeyboardShortcut(e, key, true);
<a name="line940"></a>  assertTrue(result);
<a name="line941"></a>
<a name="line942"></a>  FIELDMOCK.$verify();
<a name="line943"></a>}
<a name="line944"></a>
<a name="line945"></a>function testKeyboardShortcut_other() {
<a name="line946"></a>  FIELDMOCK.$reset();
<a name="line947"></a>  FIELDMOCK.$replay();
<a name="line948"></a>
<a name="line949"></a>  var e = {};
<a name="line950"></a>  var key = &#39;a&#39;;
<a name="line951"></a>  var result = FORMATTER.handleKeyboardShortcut(e, key, true);
<a name="line952"></a>  assertFalse(result);
<a name="line953"></a>
<a name="line954"></a>  FIELDMOCK.$verify();
<a name="line955"></a>}
</pre>


</body>
</html>
